﻿#ifndef PRODUCTLIBRARYSTANDARDITEMMODEL_H
#define PRODUCTLIBRARYSTANDARDITEMMODEL_H

#include <QStandardItemModel>
#include "product.h"

class ProductLibraryStandardItemModel : public QStandardItemModel
{
    Q_OBJECT
public:
    explicit ProductLibraryStandardItemModel(QObject *parent = nullptr);

    QStringList header;

    bool setData(const QModelIndex &index, const QVariant &value, int role) override;

    QVariant data(const QModelIndex &index, int role) const override;

    void reset();

    void insertProduct(Product &product, int defaultCount);

    void insertProduct(QList<Product*> products, int defaultCount);

    /**
     * 刷新合计
     * @brief refreshTotalValue
     */
    void refreshTotalValue();

    QList<Product*> currentProducts();
signals:
    void updateTotalValue(int totalCount, double totalMoney);

public slots:

private:
    QList<Product*> products;

    int sanbaoCountIndex;
    int inPriceIndex;
};

#endif // PRODUCTLIBRARYSTANDARDITEMMODEL_H
